//+------------------------------------------------------------------+
//|                                                 tradeManager.mqh |
//|                                                    Dimitri Rudel |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Dimitri Rudel"
#property link      ""


extern double exExitMaxRsi = 70;
extern double exExitMinRsi = 30; 


void tmgr_checkExit(){
   for(int i=0; i < OrdersTotal(); i++) {
      if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
  
         if ( OrderSymbol()==Symbol()) {
            if(exitByRsi(OrderType())){
               OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),3,Red);
            }                
         }
      }
   }
}

bool exitByRsi(int opTrade){
  double rsi = iRSI(Symbol(),0,14,PRICE_CLOSE,1);

  if(opTrade == 0){
      if(rsi > exExitMaxRsi){

         return (true);
      }
  }else{
      if(rsi < exExitMinRsi){

         return (true);

      }
  }
  return (false);
}